var express = require("express");

//md5
// var md5 = require("md5");
// session
var session = require("express-session");
//中间件连接数据库
var MongoStore = require("connect-mongo")(session);




var app = express();

app.use(express.urlencoded({ extended: false }));
app.use(express.static("public"));

var mongoose = require("mongoose");

// session的配置
app.use(
  session({
    secret: "myuser",
    rolling: true,
    cookie: {
      maxAge: 1000 * 60 * 60,
    },
    store: new MongoStore({
      url: "mongodb://127.0.0.1:27017/addstuajax",
    }),
  })
);


app.use((req, res, next)=>{
    res.set('Access-Control-Allow-Origin', '*');
    next();
});

//学生信息添加
var AddstuRouter = require("./router/Addstu");
app.use(AddstuRouter);

//学生信息修改
var RegstuRouter = require("./router/Regstu");
app.use(RegstuRouter);

//信息显示
var indexRouter = require("./router/index");
app.use(indexRouter);

//查询
var searchRouter = require("./router/search");
app.use(searchRouter);



app.listen(5555, function () {
    console.log("服务器启动...");
  });
  